﻿package com.wandian.view.mediator.bank
{
	import com.wandian.controller.AccountCommand;
	import com.wandian.controller.BankCommand;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.BankProxy;
	import com.wandian.model.InRoomPlayerDataProxy;
	import com.wandian.model.SwfDataProxy;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.FormatMoney;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.GolbalTimer;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.MaskTipPanel;
	import com.wandian.view.components.ui.bank.DepositPanel;
	import com.wandian.view.components.ui.bank.ModifyPWPanel;
	import com.wandian.view.components.ui.bank.OpenBankPanel;
	import com.wandian.view.components.ui.bank.RecordBankPanel;
	import com.wandian.view.components.ui.bank.TransferPanel;
	import com.wandian.view.components.ui.bank.WithdrawPanel;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;

    public class BankMediator extends Mediator
    {
        private var _tabBar:CLZTabBar;
        private var _mcConten:Sprite;
        private var _mcDeposit:DepositPanel;
        private var _mcModifyPW:ModifyPWPanel;
        private var _mcRecordBank:RecordBankPanel;
        private var _mcTransfer:TransferPanel;
        private var _mcWithdraw:WithdrawPanel;
        private var _mcOpenBank:OpenBankPanel;
        private var _global:GameData;
        public static const NAME:String = "BankMediator";

        public function BankMediator(param1:Object = null)
        {
            this._mcConten = new Sprite();
            this._global = GameData.getInstance();
            super(NAME, param1);
            return;
        }

        override public function onRegister() : void
        {
            var _loc_3:Sprite = null;
            facade.registerProxy(new BankProxy());
            facade.registerCommand(CLZNoticeName.BANK_COMMIT_OPEN_REQ, BankCommand);
            facade.registerCommand(CLZNoticeName.BANK_COMMIT_DEPOSIT_GOLD_REQ, BankCommand);
            facade.registerCommand(CLZNoticeName.BANK_COMMIT_WITHDRAW_GOLD_REQ, BankCommand);
            facade.registerCommand(CLZNoticeName.BANK_COMMIT_TRANSFER_GOLD_REQ, BankCommand);
            facade.registerCommand(CLZNoticeName.BANK_COMMIT_MODIFY_REQ, BankCommand);
            facade.registerCommand(CLZNoticeName.BANK_COMMIT_RECORD_REQ, BankCommand);
            this._mcDeposit = new DepositPanel();
            this._mcModifyPW = new ModifyPWPanel();
            this._mcRecordBank = new RecordBankPanel();
            this._mcTransfer = new TransferPanel();
            this._mcWithdraw = new WithdrawPanel();
            this._mcOpenBank = new OpenBankPanel();
            this.mcBank.title_txt.text = GameData.tip["BANK_PERSON_TITLE"];
            AddBtn.initBtn(this.mcBank, CLZNoticeName.HIDE_BANK_PANEL, AddBtn.CLOSE_TWO, "", 4, 1);
            this.mcBank.addChild(this._mcConten);
            this._mcConten.x = 15;
            this._mcConten.y = 116;
            var _loc_1:Array = [[this.mcBank.deposit_btn, GameData.tip["DEPOSIT_GOLD_BANK"]], [this.mcBank.withdraw_btn, GameData.tip["WITHDRAW_GOLD_BANK"]], [this.mcBank.transfer_btn, GameData.tip["TRANSFER_BANK"]], [this.mcBank.modify_btn, GameData.tip["MODIFY_BANK"]], [this.mcBank.record_btn, GameData.tip["RECORD_BANK"]]];
            this.mcBank.transfer_btn.visible = false;
            this._tabBar = new CLZTabBar(_loc_1);
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_1[_loc_2][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
                _loc_2 = _loc_2 + 1;
            }
            if (this._global.userInfo.userVo.bankpasswd)
            {
                if (this._global.userInfo.userVo.vip == 0)
                {
                    this._tabBar.setClickIndex(this.mcBank.withdraw_btn);
                }
                else
                {
                    this._tabBar.setClickIndex(this.mcBank.deposit_btn);
                }
            }
            else
            {
                _loc_3 = GameData.getSprite("OpenBankPanel");
                this._mcOpenBank.setPanel(_loc_3);
                this._mcConten.addChild(_loc_3);
            }
            this.sendNotification(CLZNoticeName.UPDATE_BANKASSETS, this._global.userInfo.userVo.bankAssets);
            this.sendNotification(CLZNoticeName.UPDATE_GOLD, this._global.userInfo.userVo.money);
            return;
        }

        private function changeTabBarHandler(event:Event) : void
        {
            var _loc_2:Sprite = null;
            if (!this._global.userInfo.userVo.bankpasswd)
            {
                this.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip:GameData.tip["PLEAS_OPEN_BANK"]});
                return;
            }
            if (this._global.userInfo.userVo.vip == 0)
            {
            }
            if (event.target.name != "withdraw_btn")
            {
                this.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip:GameData.tip["BANK_NO_VIP_TIP"]});
                return;
            }
            GameData.removeNumChildre(this._mcConten);
            switch(event.target.name)
            {
                case "deposit_btn":
                {
                    _loc_2 = GameData.getSprite("DepositPanel");
                    this._mcDeposit.setPanel(_loc_2);
                    break;
                }
                case "withdraw_btn":
                {
                    _loc_2 = GameData.getSprite("WithdrawPanel");
                    this._mcWithdraw.setPanel(_loc_2);
                    break;
                }
                case "transfer_btn":
                {
                    _loc_2 = GameData.getSprite("TransferPanel");
                    this._mcTransfer.setPanel(_loc_2);
                    break;
                }
                case "modify_btn":
                {
                    _loc_2 = GameData.getSprite("ModifyPanel");
                    this._mcModifyPW.setPanel(_loc_2);
                    break;
                }
                case "record_btn":
                {
                    _loc_2 = GameData.getSprite("RecordBankPanel");
                    this._mcRecordBank.setPanel(_loc_2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            this._mcConten.addChild(_loc_2);
            return;
        }

        override public function listNotificationInterests() : Array
        {
            return [CLZNoticeName.HIDE_BANK_PANEL, CLZNoticeName.BANK_COMMIT_OPEN_RES, CLZNoticeName.BANK_COMMIT_MODIFY_RES, CLZNoticeName.BANK_COMMIT_RECORD_RES, CLZNoticeName.UPDATE_BANKASSETS, CLZNoticeName.UPDATE_GOLD];
        }

        override public function handleNotification(param1:INotification) : void
        {
            var _loc_2:Object = null;
            switch(param1.getName())
            {
                case CLZNoticeName.HIDE_BANK_PANEL:
                {
                    this.removeBank();
                    break;
                }
                case CLZNoticeName.BANK_COMMIT_OPEN_RES:
                {
                    this._global.userInfo.userVo.bankpasswd = 1;
                    this._tabBar.setClickIndex(this.mcBank.deposit_btn);
                    break;
                }
                case CLZNoticeName.UPDATE_BANKASSETS:
                {
                    this.mcBank.deposit_txt.htmlText = GameData.tip["DEPOSIT_BANK"] + ":<font size=\'16\' color=\'#ffff00\'>" + FormatMoney.setFormatMoney(this._global.userInfo.userVo.bankAssets) + GameData.tip["GOLD"] + "</font>";
                    break;
                }
                case CLZNoticeName.UPDATE_GOLD:
                {
                    this.mcBank.stake_txt.htmlText = GameData.tip["STAKE_BANK"] + ":<font size=\'16\' color=\'#ffff00\'>" + FormatMoney.setFormatMoney(this._global.userInfo.userVo.money) + GameData.tip["GOLD"] + "</font>";
                    break;
                }
                case CLZNoticeName.BANK_COMMIT_MODIFY_RES:
                {
                    break;
                }
                case CLZNoticeName.BANK_COMMIT_RECORD_RES:
                {
                    _loc_2 = param1.getBody();
                    this._mcRecordBank.showRecordList(_loc_2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function removeBank() : void
        {
            GameData.removeNumChildre(this._mcConten);
            this._mcDeposit = null;
            this._mcModifyPW = null;
            this._mcRecordBank = null;
            this._mcTransfer = null;
            this._mcWithdraw = null;
            facade.removeProxy(BankProxy.NAME);
            facade.removeMediator(BankMediator.NAME);
            facade.removeCommand(CLZNoticeName.BANK_COMMIT_OPEN_REQ);
            facade.removeCommand(CLZNoticeName.BANK_COMMIT_DEPOSIT_GOLD_REQ);
            facade.removeCommand(CLZNoticeName.BANK_COMMIT_WITHDRAW_GOLD_REQ);
            facade.removeCommand(CLZNoticeName.BANK_COMMIT_TRANSFER_GOLD_REQ);
            facade.removeCommand(CLZNoticeName.BANK_COMMIT_MODIFY_REQ);
            facade.removeCommand(CLZNoticeName.BANK_COMMIT_RECORD_REQ);
            if (this.mcBank == null)
            {
                return;
            }
            if (Texas.I._mcWindosView.contains(this.mcBank))
            {
                Texas.I._mcWindosView.removeChildTo(this.mcBank);
                viewComponent = null;
            }
            return;
        }

        private function get mcBank() : MovieClip
        {
            return viewComponent as MovieClip;
        }

    }
}
